from app import db
class Users(db.Model):
    __tablename__ = 'users'

    openid = db.Column(db.String(64), primary_key=True)
    nickName = db.Column(db.String(64), nullable=True)
    gender = db.Column(db.String(2), nullable=True)
    language = db.Column(db.String(32), nullable=True)
    city = db.Column(db.String(32), nullable=True)
    province = db.Column(db.String(32), nullable=True)
    country = db.Column(db.String(32), nullable=True)
    avatarUrl = db.Column(db.String(128), nullable=True)

    def __init__(self, openid,nickName,gender,language,city,province,country,avatarUrl):
        self.openid = openid
        self.nickName = nickName
        self.gender = gender
        self.language = language
        self.city = city
        self.province = province
        self.country = country
        self.avatarUrl = avatarUrl

    def save(self):
        db.session.add(self)
        db.session.commit()

    def to_json(self):
        dict = self.__dict__
        if "_sa_instance_state" in dict:
            del dict["_sa_instance_state"]
        return dict